import java.io.*;

/**
 * Created by foredawn on 15-8-28.
 * 过滤流：DataInputStream和DataOutputStream
 */
public class DataStream {
    static String fileName = StreamReuse.class.getClassLoader().getResource("file").getFile();

    public static void main(String[] args) {
        write();
        read();

    }

    public static void write() {
        try (DataOutputStream out = new DataOutputStream(
                new FileOutputStream(fileName + ".data"))) {
            out.writeLong(111111111); // 写入一串Long类型数据
            out.writeBoolean(false); //写入一个Boolean类型
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void read() {
        try (DataInputStream input = new DataInputStream(
                new FileInputStream(fileName + ".data"))
        ) {
            Long lon = input.readLong();
            Boolean is = input.readBoolean();
            System.out.println(lon);
            System.out.println(is);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
